//
//  HelpTabBarController.m
//  一点互助
//
//  Created by 张泊秋 on 16/8/19.
//  Copyright © 2016年 zhangboqiu. All rights reserved.
//

#import "HelpTabBarController.h"
#import "HomePageViewController.h"
#import "MyViewController.h"
#import "ProjectViewController.h"
#import "MessageViewController.h"
#import "UserModel.h"
#import "MemberViewController.h"


@interface HelpTabBarController ()<UITabBarControllerDelegate>
@property (nonatomic, strong)NSMutableArray *navArr;

@end

@implementation HelpTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    [self tabBarAddSubVC:[[HomePageViewController alloc]init] title:@"首页" imageName:@"首页"];
    [self tabBarAddSubVC:[[ProjectViewController alloc]init] title:@"项目" imageName:@"项目"];
    [self tabBarAddSubVC:[[MessageViewController alloc]init] title:@"消息" imageName:@"消息"];
    [self tabBarAddSubVC:[[MyViewController alloc]init] title:@"我的" imageName:@"我的"];
    self.viewControllers = self.navArr;
}

- (void)tabBarAddSubVC:(UIViewController *)VC title:(NSString *)title imageName:(NSString *)imageName {
    VC.tabBarItem.title = title;
    
    [VC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:83.0f / 255.0f green:87.0f / 255.0f blue:87.0f / 255.0f alpha:1],NSFontAttributeName:[UIFont systemFontOfSize:14]} forState:0];
    
     [VC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:84.0f / 255.0f green:205.0f / 255.0f blue:198.0f / 255.0f alpha:1],NSFontAttributeName:[UIFont systemFontOfSize:14]} forState:3];
    
    VC.tabBarItem.image = [UIImage imageNamed:[NSString stringWithFormat:@"icon-%@",imageName]];
    
    VC.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"icon-%@",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
     UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:VC];
    [nav.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:16]}];
    nav.navigationBar.barTintColor = BLUE_COLOR;
    
    
    [self.navArr addObject:nav];
    
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    if ([viewController.tabBarItem.title isEqualToString:@"消息"]) {
        UserModel *model = [UserModel sharedUserModel];
        if (model.islogin == YES) {
            return YES;
        }else {
            
            MemberViewController *memberVC = [[MemberViewController alloc]init];
//            [self.navigationController pushViewController:memberVC animated:YES];
            self.selectedIndex = 3;
            
            UINavigationController *navi =  self.viewControllers[3];
            [navi pushViewController:memberVC animated:YES];
            return NO;
            
        }
    }else {
        return YES;
    }
}

- (NSMutableArray *)navArr {
    if (!_navArr) {
        _navArr = [NSMutableArray array];
    }
    return  _navArr;
}



@end
